package demo2.domain;

import java.time.format.DateTimeFormatter;

public class MaskedStudentRecord {
    private final Long id;
    public Long getId() {
        return id;
    }

    private final String name;
    public String getName() {
        return name;
    }

    private final String dob;
    public String getDob() {
        return dob;
    }

    public MaskedStudentRecord(Student student) {
        id = student.getId();
        char[] fullName = student.getName().toCharArray();
        int i = 1;
        while (i < fullName.length) {
            fullName[i] = '*';
            i++;
        }
        if (fullName.length > 2) {
            fullName[fullName.length-1] = student.getName().charAt(fullName.length-1);
        }
        name = String.valueOf(fullName);
        char[] value = DATE_TIME_FORMATTER.format(student.getDob()).toCharArray();
        value[3] = '*';
        value[9] = '*';
        dob = String.valueOf(value);
    }
    private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
}
